package cn.elricyu.tt.action.army;

import net.sf.json.JSON;
import cn.elricyu.tt.action.base.AbstractAction;
import cn.elricyu.tt.bean.User;
import cn.elricyu.tt.bean.army.RightArmy;
import cn.elricyu.tt.bean.city.MyBuilding;
import cn.elricyu.tt.exception.ActionException;
import cn.elricyu.tt.util.JsonUtil;

public class RightArmyAction extends AbstractAction<MyBuilding> {
	private User self;

	public RightArmyAction(User self) {
		this.self = self;
		this.url = "root/mainCity!rightArmy.action";
	}

	@Override
	public void process(JSON json) throws ActionException {
		int state = JsonUtil.getIntValue(json, "state", 0);
		RightArmy rightArmy = self.getMyArmy().getRightArmy();
		if (state == 1) {
			long cde = JsonUtil.getLongValue(json, "cde", 0l);
			long rightcd = JsonUtil.getLongValue(json, "rightcd", 0l);
			int rightnum = JsonUtil.getIntValue(json, "rightnum", 0);
			int forces = JsonUtil.getIntValue(json, "playerupdateinfo.forces",
					-1);
			if (rightArmy == null) {
				rightArmy = new RightArmy();
				self.getMyArmy().setRightArmy(rightArmy);
			}
			rightArmy.setCde(cde);
			rightArmy.setRightcd(rightcd);
			rightArmy.setRightnum(rightnum);
			if (forces > 0) {
				self.getPlayerInfo().setForces(forces);
			}
		}
	}

}
